Skip to content

fix: debounce now playing toast to show correct track metadata#1338

Open
endafk wants to merge 5 commits into
caelestia-dots:mainfrom
endafk:fix/now-playing-notification-race-condition
Open

fix: debounce now playing toast to show correct track metadata#1338
endafk wants to merge 5 commits into
caelestia-dots:mainfrom
endafk:fix/now-playing-notification-race-condition

Conversation

@endafk
Copy link
Copy Markdown

@endafk endafk commented Mar 26, 2026

Problem

When pressing next/previous, the now playing toast shows the previous track instead of the new one.

Root cause

Some MPRIS players (notably Spotify and Google Chrome) emit postTrackChanged in two D-Bus phases:

  1. First signal: mpris:trackid updates to the new track, but xesam:title/xesam:artist still carry the old track's values
  2. Second signal: the actual title and artist arrive

onPostTrackChanged was firing immediately on phase 1, reading stale metadata and displaying the wrong song in the notification.

Fix

Defer the toast via a Timer { interval: 300 }. The handler now calls nowPlayingTimer.restart() instead of showing the toast directly. If postTrackChanged fires again within 300ms (the second metadata update), the timer resets — so only one notification fires, after the metadata has settled.

Some MPRIS players (e.g. Spotify) emit postTrackChanged as soon as the
track ID changes over D-Bus, before the title/artist properties are
updated in a follow-up signal. This caused the now playing notification
to display the previous track's metadata instead of the new one.

Fix by deferring the toast via a 300ms Timer. If postTrackChanged fires
again within that window (second metadata update), the timer restarts,
so only one notification is shown once the metadata has settled.
Copilot AI review requested due to automatic review settings March 26, 2026 02:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes incorrect “Now Playing” toast metadata by debouncing MPRIS postTrackChanged handling so notifications fire after player metadata settles (notably for Spotify’s two-phase D-Bus updates).

Changes:

  • Route postTrackChanged handling through a 300ms Timer to debounce the toast.
  • Add QtQuick import to use Timer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread services/Players.qml
Comment thread services/Players.qml
endafk and others added 2 commits March 26, 2026 05:31
@soramanew
Copy link
Copy Markdown
Collaborator

Hmm, I use spotify and the media toasts work fine. There is only one on song change and it displays the track correctly.

@endafk
Copy link
Copy Markdown
Author

endafk commented Mar 26, 2026

Hmm, I use spotify and the media toasts work fine. There is only one on song change and it displays the track correctly.

I pretty use Gapless(g4music) and chrome(Youtube and Youtube Music) and I get a toast of the previous song whenever I use next. Whenever music stops. I also receive a toast of the music that was playing before I stoppped. Everytime there is an update, I have to redo the 300ms delay manually on the qml file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants